package com.yuanduo_app.manager;

import com.facebook.react.bridge.NativeModule;
import com.xujl.fastlib.base.BaseModule;

import java.util.ArrayList;
import java.util.List;

public class RNModuleManager {
    private List<BaseModule> mModuleList = new ArrayList<>();


    public void initAdd (List<NativeModule> list) {
        mModuleList.clear();
        for (NativeModule module : list) {
            mModuleList.add((BaseModule) module);
        }
    }

    public <T extends BaseModule> T getModule (Class<T> cls) {
        for (BaseModule module : mModuleList) {
            if (module.getClass() == cls) {
                return (T) module;
            }
        }
        return null;
    }

    public static RNModuleManager getInstance () {
        return Holder.ourInstance;
    }

    private RNModuleManager () {
    }

    private static class Holder {
        private static final RNModuleManager ourInstance = new RNModuleManager();
    }
}
